#ifndef __DEBUG_H__
#define __DEBUG_H__

#define WSGEVENT_PID_FILE              "wsgevent.pid"
#define WSGLOGDOMAINSOCKET             "/tmp/log" //"/dev/log"

#define NONEC         "\033[m"  

#define RED          "\033[0;32;31m"
#define LIGHT_RED    "\033[1;31m"
#define GREEN        "\033[0;32;32m"
#define LIGHT_GREEN  "\033[1;32m"
#define BLUE         "\033[0;32;34m"
#define LIGHT_BLUE   "\033[1;34m"
#define DARY_GRAY    "\033[1;30m"
#define CYAN         "\033[0;36m"
#define LIGHT_CYAN   "\033[1;36m"
#define PURPLE       "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN        "\033[0;33m"
#define YELLOW       "\033[1;33m"
#define LIGHT_GRAY   "\033[0;37m"
#define WHITE        "\033[1;37m"

#define SSL_PORT 7838

enum {
    RSM_NOERROR                 = 0,
    RSM_MIN_ERR                 = 1,
    RSM_ERROR_SYSERR,
};
    
static inline int rsm_isOK(int rv)
{
    return (rv == RSM_NOERROR) ? 1 : 0;
}

static inline int rsm_isError(int rv)
{
    return (rv == RSM_NOERROR) ? 0 : 1;
}

char* getAsctime(char *buf, int len);
int rsm_c_getPidFromFile(const char *pidfilename);
int rsm_fio_touchInt(const char* name, int v);

#define LEN 256
static char timeBuf[256] = "";

#define PRINTCLEAN() printf(NONEC)
#define DEBUGRED(format, args...) \
    do{printf(LIGHT_RED"time:%s pid:%d fun:%s line:%d \t" ,getAsctime(timeBuf,LEN)?(char *)timeBuf:"",getpid(),__FUNCTION__, __LINE__,getpid());\
    printf( format NONEC , ## args); sync();}while(0)
    
#define DEBUGGREEN(format, args...) \
    do{printf(LIGHT_GREEN"time:%s pid:%d fun:%s line:%d \t" ,getAsctime(timeBuf,LEN)?(char *)timeBuf:"",getpid(),__FUNCTION__, __LINE__);\
    printf( format NONEC , ## args); sync();}while(0) 

#define START DEBUGGREEN("begin\n");
#define END  DEBUGRED("end\n");

#define CR_RetCode_OK                               0
#define CR_RetCode_SYS_INVALID_ARGUMENTS            9595
#define CR_RetCode_SYS_INVALID_HEX                  9596
#define CR_RetCode_SYS_OUTOFSPACE                   9597
#define CR_RetCode_SYS_OUTOFMEMORY                  9598
#define CR_RetCode_UNZIP_FAILED                     9599
#define CR_RetCode_URL_TOO_LONG                     9696
#define CR_RetCode_URL_PATH_TOO_LONG                9697
#define CR_RetCode_URL_PORT_INVALID                 9698
#define CR_RetCode_URL_INVALID                      9699
#define CR_RetCode_HTTP_HEADER_CORRUPTED            9792
#define CR_RetCode_HTTP_RESPONSE_TOO_LARGE          9793
#define CR_RetCode_HTTP_RECV_TIMEOUT                9794
#define CR_RetCode_HTTP_AUTHENTICATE_REQUIRE        9795
#define CR_RetCode_HTTP_AUTHENTICATE_FAILED         9796
#define CR_RetCode_HTTP_STATUS_401                  9797
#define CR_RetCode_HTTP_STATUS_NOT_200              9798
#define CR_RetCode_HTTP_CHUNKED_PARSE_FAILED        9799
#define CR_RetCode_SSL_INIT_FAILED                  9899
#define CR_RetCode_SSL_CERT_NOT_FOUND               9898
#define CR_RetCode_SSL_CERT_INVALID                 9897
#define CR_RetCode_USOCKET_INIT_FAILED              9990
#define CR_RetCode_UDS_RECV_TIMEOUT                 9991
#define CR_RetCode_SOCKET_INIT_FAILED               9992
#define CR_RetCode_SOCKET_INIT_TIMEOUT              9993
#define CR_RetCode_SOCKET_RECV_TIMEOUT              9994
#define CR_RetCode_SOCKET_RECV_FAILED               9995
#define CR_RetCode_SOCKET_RECVBUF_NOT_ENOUGH        9996
#define CR_RetCode_SOCKET_SEND_FAILED               9997
#define CR_RetCode_SOCKET_SEND_TIMEOUT              9998
#define CR_RetCode_SOCKET_IP_INVALID                9999
#define CR_RetCode_SOCKET_PEER_CLOSE                9989    
#endif
